package com.webdrop.gui;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.RootPanel;
import com.webdrop.client.Login;
import com.webdrop.utils.HistoryParams;


public class MainPage implements EntryPoint,ValueChangeHandler<String>{
	private Page  myFilePage,loginPage;
	

	@Override
	public void onModuleLoad() {
		RootPanel.get().clear();
		
		loginPage=new Login();
		
		History.addValueChangeHandler(this);
		History.fireCurrentHistoryState();
	}
	
	
	@Override
	public void onValueChange(ValueChangeEvent<String> event) {
		HistoryParams p = HistoryParams.getInstance();
		
		// Remove all widgets.
		RootPanel.get("content").clear();
		
		if (!p.containsKey("page") || p.get("page").equals("login"))
		{
			RootPanel.get("content").add(loginPage);
		}

		else if (p.get("page").equals("myFilePage"))
		{
			myFilePage =new MyFiles();
			RootPanel.get("content").add(myFilePage);
		}
		
	}
}
